using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;

using Weazel.Math;

public class Controller_euclid_ctl : IController
{
    
    // The control-step the controller is executing.
    // The state the controller is currently in.
    internal Int32 CurrentControlStep;
    
    internal Int32 CurrentState;
    
    // Used to evaluate expression: m[0]
    internal Integer Value_rangeexpression142;
    
    // Used to evaluate expression: n[0]
    internal Integer Value_rangeexpression144;
    
    // Used to evaluate expression: m[0] & n[0]
    internal Integer Value_binaryexpression145;
    
    // Used to evaluate expression: m[0]
    internal Integer Value_rangeexpression148;
    
    // Used to evaluate expression: n[0]
    internal Integer Value_rangeexpression150;
    
    // Used to evaluate expression: ~n[0]
    internal Integer Value_unaryexpression151;
    
    // Used to evaluate expression: m[0] & ~n[0]
    internal Integer Value_binaryexpression152;
    
    // Used to evaluate expression: m[0]
    internal Integer Value_rangeexpression155;
    
    // Used to evaluate expression: ~m[0]
    internal Integer Value_unaryexpression156;
    
    // Used to evaluate expression: n[0]
    internal Integer Value_rangeexpression158;
    
    // Used to evaluate expression: ~m[0] & n[0]
    internal Integer Value_binaryexpression159;
    
    public virtual void Evaluate()
    {
  switch(CurrentState)
{
  case 135:
  CurrentState = 136;
  CurrentControlStep = 0;
        Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
    break;
  case 136:
        if ((Integer.Zero != Simulator.register_euclid_done.StoredValue))
        {
  CurrentState = 137;
  CurrentControlStep = 1;
            Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
        }
        else
        {
            Integer.GetRange(ref this.Value_rangeexpression142, Simulator.register_euclid_m.StoredValue, 0, 0);
            Integer.GetRange(ref this.Value_rangeexpression144, Simulator.register_euclid_n.StoredValue, 0, 0);
            Integer.And(ref this.Value_binaryexpression145, this.Value_rangeexpression142, this.Value_rangeexpression144);
            if ((Integer.Zero != this.Value_binaryexpression145))
            {
  CurrentState = 136;
  CurrentControlStep = 2;
                Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
            }
            else
            {
                Integer.GetRange(ref this.Value_rangeexpression148, Simulator.register_euclid_m.StoredValue, 0, 0);
                Integer.GetRange(ref this.Value_rangeexpression150, Simulator.register_euclid_n.StoredValue, 0, 0);
                Integer.Not(ref this.Value_unaryexpression151, this.Value_rangeexpression150);
                Integer.And(ref this.Value_binaryexpression152, this.Value_rangeexpression148, this.Value_unaryexpression151);
                if ((Integer.Zero != this.Value_binaryexpression152))
                {
  CurrentState = 136;
  CurrentControlStep = 3;
                    Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
                }
                else
                {
                    Integer.GetRange(ref this.Value_rangeexpression155, Simulator.register_euclid_m.StoredValue, 0, 0);
                    Integer.Not(ref this.Value_unaryexpression156, this.Value_rangeexpression155);
                    Integer.GetRange(ref this.Value_rangeexpression158, Simulator.register_euclid_n.StoredValue, 0, 0);
                    Integer.And(ref this.Value_binaryexpression159, this.Value_unaryexpression156, this.Value_rangeexpression158);
                    if ((Integer.Zero != this.Value_binaryexpression159))
                    {
  CurrentState = 136;
  CurrentControlStep = 4;
                        Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
                    }
                    else
                    {
  CurrentState = 136;
  CurrentControlStep = 5;
                        Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
                    }
                    if ((Integer.Zero != this.Value_binaryexpression159))
                    {
  CurrentState = 136;
  CurrentControlStep = 4;
                        Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
                    }
                    else
                    {
  CurrentState = 136;
  CurrentControlStep = 5;
                        Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
                    }
                }
            }
        }
    break;
  case 137:
  CurrentState = 137;
  CurrentControlStep = 6;
        Simulator.OutportList.Add(Simulator.outPort_euclid_gcd);
    break;
  default: // should never get here
        throw new ApplicationException();
}
    }
    
    public virtual void Initialize()
    {
        this.CurrentControlStep = 0;
        this.CurrentState = 135;

        this.Value_rangeexpression142 = new Integer(1, false);
        this.Value_rangeexpression144 = new Integer(1, false);
        this.Value_binaryexpression145 = new Integer(1, false);
        this.Value_rangeexpression148 = new Integer(1, false);
        this.Value_rangeexpression150 = new Integer(1, false);
        this.Value_unaryexpression151 = new Integer(1, false);
        this.Value_binaryexpression152 = new Integer(1, false);
        this.Value_rangeexpression155 = new Integer(1, false);
        this.Value_unaryexpression156 = new Integer(1, false);
        this.Value_rangeexpression158 = new Integer(1, false);
        this.Value_binaryexpression159 = new Integer(1, false);
    }
}

public class Controller_h_test_euclid : IController
{
    
    // The control-step the controller is executing.
    internal Int32 CurrentControlStep;
    
    public virtual void Evaluate()
    {
        Simulator.OutportList.Add(Simulator.outPort_test_euclid_m);
        Simulator.OutportList.Add(Simulator.outPort_test_euclid_n);
    }
    
    public virtual void Initialize()
    {
        this.CurrentControlStep = 0;

    }
}

